package cn.mooncode.basketballManage.exception;

import cn.mooncode.basketballManage.pojo.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @program: basketballManage
 * @description: 全局异常处理类
 * @author: jinweizhi
 * @create: 2021-03-28 10:39
 **/

@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(SQLException.class)
    public RespBean mySQLException(SQLException e) {
        if (e instanceof SQLIntegrityConstraintViolationException) {
            return RespBean.error("该数据有关联操作，删除失败！");
        }
        return RespBean.error("数据库异常，操作失败！");
    }
}
